/**
* 发布人
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>公司相关照片管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <!--        输入公司名字-->
        <el-input size="small" v-model="formInline.title" placeholder="输入公司名称"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column sortable align="center" prop="id" label="ID" width="100">
      </el-table-column>
      <el-table-column sortable align="center" prop="company.companyName" label="公司名称" width="250">
      </el-table-column>
      <el-table-column label="公司相关照片"  width="250px" >
        <template slot-scope="scope">
          <el-image :src="scope.row.img" style="width: 100px; height: 100px;"></el-image>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" prop="createTime" label="添加时间" width="250">
      </el-table-column>
      <el-table-column align="center" label="操作" max-width="100">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>

    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>

  </div>
</template>

<script>
  import { deptList, deptSave, deptDelete } from '../../api/userMG'
  import Pagination from '../../components/Pagination'
  export default {
    data() {
      return {
        isShowAddressInfo:false,
        zid:[],
        nshow: true, //switch开启
        fshow: false, //switch关闭
        loading: false, //是显示加载
        editFormVisible: false, //控制编辑页面显示与隐藏
        title: '添加',
        props: {
          lazy: true,
          lazyLoad:this.lazyLoad,
        },
        editForm: {
          //发布人id
          title:''



          //oken: loca
          // lStorage.getItem('logintoken')
        },
        // rules表单验证
        rules: {

          // companyType:[{required:true, message: '请输入公司行业类型id', trigger: 'blur' }],

        },

        formInline: {
          page: 1,
          limit: 10,
          id: '',
          title:'',


          // token: localStorage.getItem('logintoken')
        },
        // 删除部门
        seletedata: {
          ids: '',
          token: localStorage.getItem('logintoken')
        },
        userparm: [], //搜索权限
        listData: [], //用户数据
        // 分页参数
        pageparm: {
          currentPage: 1,
          pageSize: 10,
          total: 10
        }
      }
    },
    // 注册组件
    components: {
      Pagination
    },
    /**
     * 数据发生改变
     */

    /**
     * 创建完毕
     */
    created() {
      this.getdata(this.formInline)
    },

    /**
     * 里面的方法只有被调用才会执行
     */
    methods: {
      lazyLoad(node, resolve) {
        var {level} = node;
        if(level==0){
          this.$axios.get("http://localhost:8080/manage/company/getProvince",
            {params:{parentId:0}}).then((response)=>{

            var nodes=Array.from(response.data.data).map(item=>({
              value: item.id,
              label: `${item.title}`,
              leaf:level>=2
            }));
            resolve(nodes);
          });
        }else if(level==1||level==2){
          this.$axios.get("http://localhost:8080/manage/company/getProvince",
            {params:{parentId:node.value}}).then((response)=>{




            var nodes=Array.from(response.data.data).map(item=>({
              value: item.id,
              label: `${item.title}`,
              leaf:level>=2
            }));
            resolve(nodes);
          });
        }else{
          resolve(null);
        }


      },
      // 获取公司列表
      getdata(title) {

        this.loading=true
        //======================================================================================我写的
        this.$axios.get("http://localhost:8080/manage/companyPic/list",{params:{
            title:this.formInline.title,
            pageNum:this.formInline.page,
            pageSize:this.formInline.limit
          }})
          .then(res=>{
          this.loading = false
          if (res.data.msg != "success") {
            this.$message({
              type: 'info',
              message: res.data.msg
            })
          } else {
            this.listData = res.data.companyPicPageInfo.list;
            // 分页赋值
            this.pageparm.currentPage =  res.data.companyPicPageInfo.pageNum
            this.pageparm.pageSize =  res.data.companyPicPageInfo.pageSize
            this.pageparm.total = res.data.companyPicPageInfo.total
          }
        })
          .catch(err => {
            console.log(err);
            this.loading = false
            this.$message.error('公司相关照片信息加载失败，请稍后再试！')
          })
      },
      // 分页插件事件
      callFather(parm) {
        this.formInline.page = parm.currentPage
        this.formInline.limit = parm.pageSize
        this.getdata(this.formInline)
      },
      // 搜索事件
      search() {
        this.getdata(this.formInline);
      },
      // 删除公司相关照片
      deleteUser(index, row) {
        this.$confirm('确定要删除吗?', '信息', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            //this.$axios.post("http://localhost:8080/manage/insert",this.editForm)
            this.$axios.get("http://localhost:8080/manage/companyPic/delete?id="+row.id)//delete?id="+id
              .then(res => {
                if (res.data) {
                  this.$message({
                    type: 'success',
                    message: '发布人已删除!',
                  })
                  this.getdata(this.formInline)

                } else {
                  this.$message({
                    type: 'info',
                    message: res.data.msg
                  })
                }
              })
              .catch(err => {
                this.loading = false
                this.$message.error('公司删除失败，请稍后再试！')
              })
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
      },
      // 关闭编辑、增加弹出框
      closeDialog() {
        this.editFormVisible = false
      }
    }
  }
</script>

<style scoped>
  .user-search {
    margin-top: 20px;
  }
  .userRole {
    width: 100%;
  }
</style>

